package scoping.blocks;

import ic.ast.stmt.LocalVariable;

import java.util.List;

import scoping.helpers.FaultyType.FaultType;
import scoping.helpers.ScopeException;

public class StmtBlockScope extends ScopeBlock {
	private boolean _isWhile = false;
	private List<LocalVariable> _localVars;
	private boolean _isOneLiner;
	
	public StmtBlockScope(List<LocalVariable> variables) throws ScopeException{
		_localVars = variables;
		populateVariables(variables);
		_isOneLiner = false;
	}
	
	public StmtBlockScope(List<LocalVariable> variables, boolean isOneLiner) throws ScopeException{
		_localVars = variables;
		populateVariables(variables);
		_isOneLiner = isOneLiner;
	}
	
	public List<LocalVariable> getLocalVars(){
		return _localVars;
	}
	
	private void populateVariables(List<LocalVariable> vars) throws ScopeException
	{
		for (LocalVariable var : vars)
		{
			
			if (! TestAndSet(_variables, var.getName(), var.getType()))
			{
				throw new ScopeException(var.getLine(),String.format(FaultType.DEFINED.getDescription(), var.getName()));
			}

		}
	}
	
	public boolean getIsWhile()
	{
		return this._isWhile;
	}
	
	public boolean getIsOneLiner(){
		return this._isOneLiner;
	}
	
	public void setIsWhile(boolean isWhile)
	{
		this._isWhile = isWhile;
	}
}
